const spawn = require('child_process').spawn
const callfile = require('child_process');

 

class MainTool{ 
  
  // currentPath 执行脚本的目录  sh_path 对引的sh 脚本地址
  static async deploymentApp(sh_path ,currentPath){
    let msg = await this.rumCommand('expect', [sh_path] , currentPath , (txt)=>{
         console.log(`在${currentPath}目录下执行了脚本${sh_path}`);
         console.log(txt);
    })
    return msg
  } 

  // 创建子进程 执行指定脚本
  static async rumCommand( cmd, args , currentPath, callback ) {
    var child = spawn( cmd, args, {
      cwd: currentPath,
    } )
    var response = ''
    child.stdout.on('data', function( buffer ){
     response += buffer.toString(); 
    })

    child.stdout.on('end', function(){ 
      callback( response ) 
      return response
    })
  } 

}

module.exports = MainTool